<?php
/**
 * Created by PhpStorm.
 * User: zzw
 * Date: 17-3-17
 * Time: 下午3:45
 */
class balance extends API_Controller
{
    protected $rules = array(
        "balance" => array(
            array(
                'field' => 'rid',
                'label' => '关注用户',
                'rules' => 'trim|required|numeric|callback_rid_check',
            ),
        )
    );

    public function __construct()
    {
        parent::__construct();
        $this->_auto();
        $this->load->model('balance_detail_model', 'mbalance');
    }
    //钱包明细列表
    public function blist() {
        $where = array('uid' => $this->userinfo['id']);
        $this->_list();
        $this->orderby = array('created_at'=>'desc','pay_time'=>'desc');
        $this->Fields = 'id,type,title,title_url,money,status,pay_ways,pay_time,created_at';
        $list = $this->mbalance->get_list($this->limit, $this->offset, $this->orderby, $where, $this->Fields);
        foreach($list as &$row) {
            $row = $this->mbalance->status_desc($row,false);
            $row['created_at'] = date('Y-m-d H:i:s',$row['created_at']);
        }
        $this->vdata['returnCode'] = '200';
        $this->vdata['returnInfo'] = '操作成功';
        $this->vdata['secure'] = JSON_SECURE;
        $this->vdata['content'] = $list;
        // 返回json数据
        $this->_send_json($this->vdata);
    }
    //钱包详情
    public function detail() {
        $where = array('id'=>$this->data['id'],'uid' => $this->userinfo['id']);
        $detail = $this->mbalance->get_one($where);
        if ($detail) {
            $account = $this->macc->get_one($detail['rid'],'uname,photo');
            $detail['photo'] = one_upload($account['photo']);
            $detail['photo'] = UPLOAD_URL.$detail['photo']['url'];
            $detail['uname'] = $account['uname'];
            $detail = $this->mbalance->status_desc($detail);
            $detail['created_at'] = date('Y-m-d H:i:s',$detail['created_at']);
            $this->vdata['returnCode'] = '200';
            $this->vdata['returnInfo'] = '操作成功';
            $this->vdata['secure'] = JSON_SECURE;
            $this->vdata['content'] = $detail;
        } else {
            $this->vdata['returnCode'] = '200';
            $this->vdata['returnInfo'] = '操作失败';
            $this->vdata['content'] = '';
        }
        $this->_send_json($this->vdata);
    }


}